WaveInAddBuffer a NT
Otázka od: Tomas Jantac
30. 10. 2003 11:46
Ahoj,
nema tu nekdo zkusenosti s jednotkou MMSystem? Konkretne se samplovanim zvuku?
Mam kod, jehoz cast je uvedena dole, ktery mi pod Windows XP a Windows 2000
chodi ale pod Windows NT ne i kdyz na MSDN je uvadena podpora na vsech OS.
Aplikace funguje dokud se nevola procedure WaveInAddBuffer (misto v kodu je
oznaceno {**}), tam se zastavi aniz by vratila nejakou vyjimku, nebo navratovou
hodnotu. Princip celeho algoritmu je nasledujici: Alokuji se dva buffery pro
samplovani zvuku, ktere se stridave podstrkavaji systemu pomoci funkci
WaveInAddBuffer a pri volani funkce WaveInProc se naplneny buffer zpracuje,
vyprazdni (resp. znovu se pripravi hlavicka) a opet se funkci WaveInAddBuffer
zaradi do fronty pro saplovani. (samplovani se spousti funkci StartSampling)
Diky za pripadne rady/napady....
Tomas J.
D7 Prof
procedure waveInProc(SomeWaveIn: HWaveIn; uMsg: UINT; dwInstance,
dwParam1, dwParam2: DWORD); begin
case uMsg of // Respond to WaveIn messages from Windows.
WIM_OPEN: PostMessage(fMain.Handle, WaveIn_Started, 0,
dwParam1); WIM_CLOSE: PostMessage(fMain.Handle, WaveIn_Stop,
0, dwParam1); WIM_DATA: fMain.ContinueRecording(dwParam1);
end;
end;
function TfMain.ContinueRecording(WAVEHDRPtr: Integer): Boolean;
var
P:Pointer;
I,C:Integer;
begin
TempWavHdr := PWAVEHDR(WAVEHDRPtr);
If not Stoping then
begin
EnterCriticalSection(cSocket);
try
if Assigned(gSocket) then
gSocket.SendBuf(TempWavHdr.lpData^,TempWavHdr.dwBytesRecorded);
finally
LeaveCriticalSection(cSocket);
end;
P:=TempWavHdr.lpData;
ResetBufferHeader(TempWavHdr,P);
I:=waveInPrepareHeader(FInputHandle, TempWavHdr,
SizeOf(WAVEHDR)); try
{**} I:=waveInAddBuffer(FInputHandle, TempWavHdr,
SizeOf(WAVEHDR)); {** tady se to zastavi **} except
end;
Result := True;
end
else
begin
Result:=True;
For I:=Low(fWaveHeader) to High(fWaveHeader) do
begin
c:=waveInUnprepareHeader(FInputHandle,fWaveHeader[I],SizeOf(WaveHdr));
Result:=Result And (C=MMSYSERR_NOERROR);
end; {}
try
If Result then PostMessage(fMain.Handle, UM_MyStop, 0, 0);
except
end;
end;
Memo1.Lines.Add('continueRecording
End'+IntToStr(Ord(Stoping))); end;
Procedure
TfMain.ResetBufferHeader(WaveHeader:PWaveHdr;WaveBuffer:Pointer);
begin
WaveHeader^.lpData:=WaveBuffer;
WaveHeader^.dwBufferLength:=BufferBlockSize;
WaveHeader^.dwBytesRecorded:=0;
WaveHeader^.dwFlags:=0;
WaveHeader^.lpNext:=nil;
end;
function TfMain.StartSampling(Node:IXMLNode): IXMLNode;
{} function GetWaveFormatEx(Node:IXMLNode):TWaveFormatEx;
{} begin
{} Result.nChannels:=GetAttribute(Node,'Chanels',2);
{}
Result.nSamplesPerSec:=GetAttribute(Node,'SamplesPerSec',2048);
{} Result.wFormatTag:=WAVE_FORMAT_PCM;
{} Result.wBitsPerSample:=GetAttribute(Node,'BitsPerSample',8);
{}
Result.nBlockAlign:=Round((Result.nChannels*Result.wBitsPerSample)/8);
{}
Result.nAvgBytesPerSec:=Result.nSamplesPerSec*Result.nBlockAlign;
{} Result.cbSize:=0;
{} end;
{} Function GetWaveHeader:PWaveHdr;
{} var WaveBuffer:Pointer;
{} begin
{} Result:=AllocMem(sizeOf(WaveHdr));
{} WaveBuffer:=AllocMem(BufferBlockSize);
{} ResetBufferHeader(Result,WaveBuffer);
{} end;
Var I:Integer;
WFEx:TWaveFormatEx;
B:Boolean;
begin
Result:=nil;
Stoping:=False;
If not Assigned(Node) then
Node:=XMLconfig.DocumentElement.ChildNodes['format'];
WFEx:=GetWaveFormatEx(Node);
B := waveInOpen(@FInputHandle, DevId, (@WFEx),
DWord(@WaveInProc), DWORD(Application.MainForm.Handle),
DWORD(callback_function)) = MMSYSERR_NOERROR;
SetLength(fWaveHeader,MaxBuffers);
For I:=Low(fWaveHeader) to High(fWaveHeader) do
begin
fWaveHeader[I]:=GetWaveHeader;
waveInPrepareHeader(FInputHandle,fWaveHeader[I],sizeOf(WAVEHDR));
waveInAddBuffer(FInputHandle,fWaveHeader[I],SizeOf(WAVEHDR));
end;
if B then B:=B and
(waveInStart(FInputHandle)=MMSYSERR_NOERROR); if B then
Result:=Node;
end;
----------
* www.inMail.sk - Vasa emailova adresa na cely zivot ZDARMA
* Mail neobsahuje virusy. Zkontrolovane antivirusom NOD32 (www.eset.sk)
* www.SlovakNET.sk - profesionalny webhosting, domena .SK ZADARMO
* Zoner Media Explorer 5 - stiahnite si pomocnika pre digitalnu fotografiu
(zme.zoner.sk)